import random
import marshal
f1 = open('dict')
links = marshal.load(f1)

f2 = open('titles')
titles = marshal.load(f2)


numberOfW = links[-1]
last = 0

def printMe(scores, rounds ):
        wszystkie = 0
        answer = [] 
        
        for elem in titles:
            answer.append( ( float( scores[titles[elem]] ) / ( rounds ) , elem ) )
            wszystkie += scores[titles[elem]]

        answer.sort(reverse = True)
        
        f = open('pagerank.txt','w')
        for elem in answer:
            f.write( elem[1] + ' ## ' + str(elem[0] ) + '\n' )
        f.close()

        print rounds
        print wszystkie
   

import iteruj

iteruj.init(numberOfW)
score = []

for elem in range(numberOfW):
    score.append( 0 )
    
for elem in links:
    if elem != -1:
        iteruj.putLinks( links[elem], elem )

if __name__ == '__main__':
    print u'Teraz policze PageRank'
    ans = iteruj.iter(score,1000000)
    print u'Teraz zapisze PageRank do pliku'
    printMe( ans, 1000000 * 100)

def getPointerToScore():
    return iteruj.score()
    
def iterujPR(l1, t, liczba ):
    iteruj.setJump(t)
    iteruj.iter2(l1,liczba)
    return liczba * 1000
